<template>
  <TheCreateForm
    ref="formRefs"
    mainKey="id"
    :options="formOptions"
    :form.sync="form"
    title="售后处理结果"
    :autoClose="false"
    @submit="onSubmit"
  >
    <template v-slot:merchantName="{ slotProps }">
      {{ merchantName }},赔款金额在商家余额中查看。
    </template>
    <template v-slot:workerName="{ slotProps }">
      {{ workerName }},扣款金额见师傅账单。
    </template>
    
  </TheCreateForm>
</template>

<script>
import {
  apiServiceSaleReturnBDispose,
  apiServiceSaleReturnBDetail,
} from "@/api/salesAfter.js";
export default {
  components: {},
  data() {
    return {
      formOptions: [
        {
          type: "textarea",
          field: "dispose",
          title: "处理结果",
          maxlength: 180,
          placeholder: "处理结果...",
          rules: [
            { required: true, message: "请输入处理结果", trigger: "blur" },
          ],
        },
        {
          type: "input-number",
          field: "merchantSaleAmount",
          title: "向商家赔款",
          controls: false,
          placeholder: "赔款金额...",
          default: undefined,
          min: 0,
          max: 9999,
          precision: 2,
          rules: [
            { required: true, message: "请输入赔款金额", trigger: "blur" },
          ],
        },
        {
          type: "input",
          field: "merchantName",
          title: "商家名称",
          slot: "merchantName",
        },
        {
          type: "input-number",
          field: "workerSaleAmount",
          title: "向师傅扣款",
          placeholder: "扣款金额...",
          default: undefined,
          controls: false,
          min: 0,
          max: 9999,
          precision: 2,
          rules: [
            { required: true, message: "请输入扣款金额", trigger: "blur" },
          ],
        },
        {
          type: "input",
          field: "workerName",
          title: "师傅姓名",
          slot: "workerName",
        },
      ],
      form: {},
      serviceSaleReturnId: "",
      liugeFlag:'',
      workerName: "",
      merchantName: "",
    };
  },
  mounted() {},
  methods: {
    onSubmit(values) {
      const params = {
        serviceSaleReturnId: this.serviceSaleReturnId,
        merchantSaleAmount: values.merchantSaleAmount*100,
        workerSaleAmount: values.workerSaleAmount*100,
        dispose: values.dispose,
      };
      apiServiceSaleReturnBDispose(params).then((res) => {
        this.$message({
          type: "success",
          message: "处理成功",
        });
        this.$refs.formRefs.close();
        this.$emit('done')

      });
    },
    open(row) {
      this.serviceSaleReturnId = row.serviceSaleReturnId;
      this.liugeFlag=row.liugeFlag
      apiServiceSaleReturnBDetail({
        serviceSaleReturnId: this.serviceSaleReturnId,
      }).then((res) => {
        this.workerName = res.data.workerName;
        this.merchantName = res.data.merchantName;
      });
      this.$refs.formRefs.open(row);
    },
  },
};
</script>

